package cfdt.ldl.dspchannel.api.feign;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClientBuilder;
import org.springframework.cloud.openfeign.FeignClientFactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import cfdt.ldl.dspchannel.api.feign.fallback.DspChannelFeignFallBackFactory;
@Component
public class DspChannelDynamicFeign {
private FeignClientBuilder builder;
    
    public DspChannelDynamicFeign(@Autowired ApplicationContext context) {
        this.builder = new FeignClientBuilder(context);
    }
    
    public DspChannelFeign getFeign(String serviceName) {
        serviceName = "DspChannel" + serviceName;
        
        FeignClientFactoryBean feignClientFactoryBean = new FeignClientFactoryBean();
        feignClientFactoryBean.setFallbackFactory(DspChannelFeignFallBackFactory.class);
        return this.builder.forType(DspChannelFeign.class, feignClientFactoryBean, serviceName).path(serviceName).build();
    }
}
